package org.lq.shopping.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.lq.shopping.dao.Shop_judgeDao;
import org.lq.shopping.dao.impl.Shop_judgeDaoImpl;
import org.lq.shopping.entity.Shop_judge;
import org.lq.shopping.service.Shop_judgeService;

import com.google.gson.Gson;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class Shop_judgeServiceImpl implements Shop_judgeService {

	Shop_judgeDao sdao = new Shop_judgeDaoImpl();
	@Override
	public List<Shop_judge> findPage(int goodsId, int pageIndex, int pageSize) {
		List<Shop_judge> list = null;
		list = sdao.findPage(pageIndex, pageSize);
//		System.out.println(list);
		
		JedisPoolConfig config = new JedisPoolConfig();
		//控制最大连接数
		config.setMaxTotal(50);
		//设置空闲连接
		config.setMaxIdle(5);
		//默认-1,等待时间,如果等待时间内没有获得连接,之间抛出异常
		config.setMaxWaitMillis(1000*100);
		//在获取连接之前,validate操作,验证  保证得到连接可用
		config.setTestOnBorrow(true);
		//当返回一个连接pool 的时候先进行ping() 判断是否可以连接
		config.setTestOnReturn(true);
		//配置接口密码
		JedisPool pool = new  JedisPool(config,"127.0.0.1",6379,2000);
		//一个redis连接对对象
		Jedis jedis = pool.getResource();
		jedis.select(8);
		
		Shop_judge sjudge = new Shop_judge();
		Gson gson = new Gson();
		
//		for(Shop_judge s :list) {
//			String s3 =gson.toJson(s);
//			jedis.lpush("s", s3);
//		}
		
		
		List<String> list1 = jedis.lrange("shop_judge", (pageIndex -1)*pageSize, pageIndex*pageSize);
		List<Shop_judge> shop_judge = new ArrayList<>();
		for (String str : list1) {
			Shop_judge s = gson.fromJson(str,Shop_judge.class);

			shop_judge.add(s);
		}
		
		
		
		return shop_judge;
	}

}
